﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace B.S.BasicData.Api.Write.Filters
{

    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class MyExcetionFilter : IExceptionFilter
    {
        private readonly ILogger<MyExcetionFilter> logger;

        public MyExcetionFilter(ILogger<MyExcetionFilter> logger)
        {
            this.logger = logger;
        }
        /// <summary>
        /// 异常拦截器处理方法
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("有全局异常发生:"+context.Exception.Message);
            context.ExceptionHandled = true;  
        }
    }
}
